package cn.funeralobjects.util;

import cn.funeralobjects.util.factory.GlobalTreadFactory;

/**
 * @author FuneralObjects
 * Create date: 2020/4/16 2:30 PM
 */
public class ThreadUtils {

    /**
     * 获取被管理的全部在执行的线程数量
     *
     * @return 线程数
     */
    public static int getAllActiveCount() {
        return GlobalTreadFactory.activeCount();
    }

    /**
     * 中断所有被被管理的线程
     */
    public static void interruptAll() {
        GlobalTreadFactory.interrupt();
    }

    /**
     * 获取当前系统中所有的在执行的线程数量
     *
     * @return 线程数
     */
    public static int getSystemAllActiveCount() {
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        ThreadGroup topGroup = group;
        while (group != null) {
            topGroup = group;
            group = group.getParent();
        }
        return topGroup.activeCount();
    }
}
